Skip to content

启动软件自更新 - SoftUpdateStart

函数简介

用户主动触发自更新:内部调用更新状态接口获取包信息,下载并校验后释放内嵌 ola_updater.exe 并启动。

仅查询是否有更新请使用 GetSoftUpdateStatus,本接口负责执行更新。

返回数据格式:

json
{
  "Code": 1,
  "Message": "updater started, please exit host process to continue",
  "HasUpdate": true,
  "NeedExit": true,
  "PackagePath": "C:\\App\\.ola_update\\cache\\1.2.0\\app.zip",
  "UpdaterPath": "C:\\App\\.ola_update\\cache\\ola_updater.exe",
  "UpdaterPid": 4321,
  "VersionNumber": "1.2.0",
  "PackageType": "zip",
  "LogDir": "C:\\App\\.ola_update\\logs"
}
字段名类型说明
Code整数1 成功;0 失败。
Message字符串结果说明或错误信息。
HasUpdate布尔是否存在可更新版本。无更新时 Code 仍可为 1。
NeedExit布尔为 true 时请退出宿主,以便 Updater 覆盖/安装。
PackagePath字符串已下载安装包本地路径。
UpdaterPath字符串已释放的 Updater 路径。
UpdaterPid整数Updater 进程 ID。
VersionNumber字符串目标版本号。
PackageType字符串ziprarexe.msi 按 exe 安装器处理)。
LogDir字符串更新日志目录(.ola_update\logs)。

接口名称

SoftUpdateStart

DLL调用

long SoftUpdateStart(string userCode, string softCode, string softVersion, string dealerCode,
                     string installRoot, string silentArgs, string launchPath, int waitPid);

参数说明

参数名类型说明
userCode字符串用户码。
softCode字符串软件码。
softVersion字符串当前软件版本。
dealerCode字符串经销商码。
installRoot字符串安装根目录(zip/rar 覆盖目标;日志/缓存也写在此)。必填
silentArgs字符串exe/msi 静默参数,原样传给安装包(如 Inno /VERYSILENT /NORESTART、NSIS /S);zip/rar 可传空。
launchPath字符串更新完成后可选拉起的主程序路径,可空。
waitPid整数等待退出的进程 PID;传 0 表示等待当前进程。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    "C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
if (result.Code == 1 && result.NeedExit) {
    // 退出宿主,让 Updater 继续
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    @"C:\App", "/S", @"C:\App\MyApp.exe", 0);
// result.NeedExit == true 时请退出宿主
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
json_result = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    r"C:\App", "/S", r"C:\App\MyApp.exe", 0)
# Python SDK 返回 JSON 字符串,需自行解析
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateStartReturn;

OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    "C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
// result.NeedExit == true 时请退出宿主
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
result := ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    `C:\App`, "/S", `C:\App\MyApp.exe`, 0)
// result.NeedExit == true 时请退出宿主
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let result = ola.soft_update_start(
    "userCode", "softCode", "1.0.0", "dealerCode",
    r"C:\App", "/S", r"C:\App\MyApp.exe", 0);
// result.need_exit == true 时请退出宿主
cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)
text
.局部变量 ola, OLAPlug
.局部变量 result, OlaSoftUpdateStartReturn
ola.创建 ()
result = ola.SoftUpdateStart(“userCode”, “softCode”, “1.0.0”, “dealerCode”, “C:\App”, “/S”, “C:\App\MyApp.exe”, 0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    "C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
// Aardio SDK 返回 JSON 字符串,需自行解析
text
变量 ola <类型 = OLAPlugServer>
变量 result <类型 = OlaSoftUpdateStartReturn>
ola = 新建 OLAPlugServer
result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
    "userCode", "softCode", "1.0.0", "dealerCode",
    "C:\\App", "/S", "C:\\App\\MyApp.exe", 0);

原生 DLL 调用

cpp
long ptr = SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode",
                           "C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
if (ptr != 0) {
    char buffer[4096] = {0};
    GetStringFromPtr(ptr, buffer, sizeof(buffer));
    FreeStringPtr(ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateStart(string userCode, string softCode, string softVersion,
    string dealerCode, string installRoot, string silentArgs, string launchPath, int waitPid);

long ptr = SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode",
    @"C:\App", "/S", @"C:\App\MyApp.exe", 0);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string result = sb.ToString();
}
python
from ctypes import CDLL, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateStart(
    b"userCode", b"softCode", b"1.0.0", b"dealerCode",
    b"C:\\App", b"/S", b"C:\\App\\MyApp.exe", 0)
if ptr:
    buf = create_string_buffer(4096)
    ola.GetStringFromPtr(ptr, buf, 4096)
    ola.FreeStringPtr(ptr)
    result = buf.value.decode("utf-8")

返回值

调用方式返回值说明
SDKOlaSoftUpdateStartReturn结构化返回对象;Code == 1 表示启动流程成功
原生 DLL非 0成功,返回 JSON 字符串指针
原生 DLL0失败

注意事项

项目说明
退出宿主返回 NeedExit=true 后必须退出占用安装目录的进程,否则 zip/rar 覆盖可能失败并回滚。
下载进度下载阶段可用 SoftUpdateGetProgress
结果查询结束后用 SoftUpdateGetLastStatus:无日志/成功 → Code=1;失败 → Code=0
失败摘要SoftUpdateGetLastError
模块说明软件自更新模块总览(含 SoftUpdateDemo 详细流程)。
释放内存原生返回指针需 FreeStringPtr